import logging

import pytest

from conm.uitils import assert_json, sql_clear, read_json
from api.reg_login_api import RegLoginApi
import requests
from conm.uitils import mysql_go


class TestRegLogin(object):

    sess = None
    @classmethod
    def setup_class(cls):
        sql_clear()
    def setup(cls):
        cls.sess = requests.session()
        cls.sp = RegLoginApi(cls.sess)
    def teardown(cls):
        cls.sess.close()
    # 获取图片验证码测试用例
    def test01_img_verify_code(self):
        resp = self.sp.get_img_verify_code(123456789323)
        assert 200 == resp.status_code
    # 获取短信验证码测试用例
    def test02_phone_verify_code(self):
        self.sp.get_img_verify_code(123456739223)
        resp = self.sp.get_phone_verify_code(13822138229)
        # resp_json = resp.json()
        # assert 200 == resp.status_code
        # assert 200 == resp_json['status']
        # assert '成功' in resp_json['description']
        assert_json(resp, 200, 200, '成功')
    # # 注册测试用例
    # def test03_register(self):
    #     self.sp.get_img_verify_code(123456789223)
    #     self.sp.get_phone_verify_code(13822138231)
    #     body = {
    #     "phone": "13822138231",
    #     "password" : "a12345",
    #     "verifycode":"8888",
    #     "phone_code" : "666666",
    #     "dy_server": "on"
    #     }
    #     resp = self.sp.user_register(body)
    #     assert_json(resp, 200, 200, '成功')
    # # 登录测试用例
    # def test04_user_login_csh(self):
    #     resp = self.sp.user_login('13822138239','qqq123')

        assert_json(resp, 200, 200, '成功')
    @pytest.mark.parametrize("body,exp_status_code,exp_code,exp_str",read_json("reg_login_data","user_register"))
    def test03_register_csh(self,body,exp_status_code,exp_code,exp_str):
        self.sp.get_img_verify_code(123456789223)
        self.sp.get_phone_verify_code(body['phone'])
        resp = self.sp.user_register(body)
        # logging.info(body,exp_status_code,exp_code,exp_str)
        assert_json(resp, exp_status_code, exp_code, exp_str)
    #

    @pytest.mark.parametrize("mobile,password,exp_status_code,exp_status,description",read_json("reg_login_data","user_login"))
    def test04_user_login_csh(self,mobile,password,exp_status_code,exp_status,description):
        resp = self.sp.user_login(mobile,password)
        assert_json(resp, exp_status_code, exp_status, description)